//
//  WLChoicePhotosView.m
//  WalnutLive
//
//  Created by 江洋大盗 on 2017/4/17.
//  Copyright © 2017年 WZYK. All rights reserved.
//

#import "TMChoicePhotosView.h"
#import "TMCardTypeCell.h"
@interface TMChoicePhotosView()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, assign) NSInteger selectIndex;
@end
@implementation TMChoicePhotosView

static TMChoicePhotosView * _choicePhotos;
+ (instancetype) choicePhotosAddToView:(UIView *)supview withType:(ChoosePhotoIV)type{
    if (!_choicePhotos) {
        _choicePhotos = [[NSBundle mainBundle] loadNibNamed:@"TMChoicePhotosView" owner:nil options:nil][0];
    }
    _choicePhotos.ChoosePhotoType = type;
    if (_choicePhotos.ChoosePhotoType == ChoosePhotoIVBankBind) {
        _choicePhotos.checkView.hidden = YES;
    }else{
        _choicePhotos.checkTab.hidden = YES;
    }
    _choicePhotos.frame = CGRectMake(0, 0, supview.bounds.size.width, supview.bounds.size.height);
    [supview addSubview:_choicePhotos];
    return _choicePhotos;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    _selectIndex = 1;
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.checkTab registerNib:[UINib nibWithNibName:@"TMCardTypeCell" bundle:nil
                                         ] forCellReuseIdentifier:@"TMCardTypeCell"];
    self.checkTab.delegate = self;
    self.checkTab.dataSource = self;
    self.checkTab.tableFooterView = [UIView new];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TMCardTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TMCardTypeCell"];
    cell.isSystem = NO;
    if (self.selectIndex == indexPath.row) {
        if (indexPath.row == 0) {
           
        }else{
        cell.bankLabel.textColor = [UIColor redColor];
    }
    }else{
        cell.bankLabel.textColor = [UIColor hx_colorWithHexRGBAString:@"#303030"];
    }
    if (indexPath.row == 0) {
        cell.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"F0F0F0"];
        cell.bankLabel.text = @"选择银行卡";
    }
    if (indexPath.row == 1) {
        cell.bankLabel.text = @"招商银行";
    }
    if (indexPath.row == 2) {
        cell.bankLabel.text = @"工商银行";
    }
    if (indexPath.row == 3) {
        cell.bankLabel.text = @"建设银行";
    }
    if (indexPath.row == 4) {
        cell.bankLabel.text = @"农业银行";
    }
    if (indexPath.row == 5) {
        cell.bankLabel.text = @"中国工商银行";
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 51*kWindowW/375;
    }else{
        return 46*kWindowW/375;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return;
    }
    self.selectIndex = indexPath.row;
    [tableView reloadData];
    [self removeFromSuperview];
}
- (IBAction)chooseByCram:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CHOOSEPHOTOACTIONCRAM" object:nil userInfo:@{@"type":@(_choicePhotos.ChoosePhotoType)}];
    [self closeBtn:nil];
}
- (IBAction)choicePhotoBtn:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CHOOSEPHOTOACTION" object:nil userInfo:@{@"type":@(_choicePhotos.ChoosePhotoType)}];
    [self closeBtn:nil];
}
- (IBAction)closeBtn:(UIButton *)sender {
    [self removeFromSuperview];
    _choicePhotos = nil;
}
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    [self removeFromSuperview];
//}
@end
